<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>

<body>
    <script>
        var money = +prompt("请输入理财金额");
        var year = +prompt("请输入理财年限");
        if (isNaN(money) || isNaN(year) || money <= 0 || year <= 0) {
            console.log("输入有误");
        } else {
            var rate = 0.04; // 年利率4%
            if (money >= 500000) {
                rate = 0.045;
            }
            var earnMoney = money * rate * year; // 收益
            if (money >= 2000000) {
                earnMoney += earnMoney * 0.1;
            }
            console.log(`总收益为：${earnMoney}`);
        }
    </script>
</body>

</html>